﻿using Microsoft.Extensions.DependencyInjection;
using OcrAndFileApi;
using SmartAPI.SmartArchive;
using SmartAPI.SmartArchive.Dto;
using System;
using System.Text.Json;
using System.Threading.Tasks;

namespace TicketOCR
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var services = new ServiceCollection();
            var jsonOptions = new JsonSerializerOptions
            {
                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };
            services.AddHttpApi<IOcrApi>()
                .ConfigureHttpApi(o =>
                {
                    o.HttpHost = new Uri("http://211.155.90.103:8506");
                    o.JsonSerializeOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                    o.JsonSerializeOptions.IgnoreNullValues = true;
                    o.JsonDeserializeOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                });
            var serviceProvider = services.BuildServiceProvider();
            var ocrApi = serviceProvider.GetService<IOcrApi>();
            var ticketResult = await ocrApi.TicketAsync(new BaseRequestDto
            {
                Image = ImageExtension.GetImage("idcard.jpg"),
                Scene = "idcard_v3"
            });
            Console.WriteLine("票据识别结果");
            Console.WriteLine(JsonSerializer.Serialize(ticketResult, jsonOptions));
        }
    }
}
